refactor: 拆分三个单体大文件(DiffSearchPanel / DraftZone / ChatInputBar)#84
Merged
Conversation
DiffSearchPanel.tsx 576 → ~190 行,退化为瘦渲染组件。新增 search/ 子目录: - search/diff-search.ts:纯跨文件搜索逻辑(runSearch + findChangedIndices / expandToContext / stripLeadingIndent / findMatchSpan / countLines / loadContent) + 类型 LineMatch / FileResults + 常量,无 React 依赖 - search/colorize.ts:colorizeAll(Monaco editor.colorize 异步语法着色) - search/useDiffSearch.ts:搜索状态机 hook(query / 大小写持久化 / 结果 / loading / 折叠态 + 去抖搜索 + 内容缓存 + 自动聚焦) 纯结构拆分,行为不变;DiffSearchPanel 导出名与路径保持不变(DiffView 引用零波及)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DraftZone.tsx 531 → ~230 行,退化为瘦渲染组件。 - useDraftZone.ts:read/edit/publish 状态机 hook —— 全部 state(isEditing / editingBody / saving / publishing / publishError / confirmDelete)+ ref(textarea + 4 个同步 ref + isMutating 锁)+ effect(ref 同步 / mutate 锁 / unmount cleanup / registerEditTrigger / draft.body 同步 / focus / Esc window listener)+ handler (runCancelLogic / handleSave / handlePublish / handlePublishFromEdit / handleCancel / handleDelete / handleConfirmDelete / onKeyDown)+ 派生(canEdit / canSave / isStash) - DraftZone.tsx:消费 hook 做渲染(head / edit / read / foot / 错误 / ConfirmModal) 取消四档逻辑(取消按钮 / unmount cleanup / Esc 共用 runCancelLogic 读 ref 最新值)整体 搬进 hook,行为不变;eslint-disable 兜底原样保留。DraftZone 导出名与路径不变。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ChatInputBar.tsx 479 → ~240 行,退化为瘦渲染组件。 - utils/parse-command.ts:纯命令解析 parseChatCommand → 判别式结果 (unknown / commandNoArgs / askNeedsQuestion / reviewAction / run / agentAsk),无 i18n / 副作用 - hooks/useChatInput.ts:输入栏状态机 hook —— 输入 / 提交(调 parseChatCommand 映射回调)/ 自动补全浮层 / 历史回放(shell 式 Up/Down)/ 停止请求 + 相关 effect - hooks/useTextareaAutosizeDrag.ts:textarea 顶边拖拽调高 - ChatInputBar.tsx:消费两个 hook 做渲染(补全列表 / textarea / 命令栏 / 自动评审 / 发送停止) 纯结构拆分,行为不变;ChatInputBar 导出名与路径不变(ChatPane 引用零波及)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
继 DiffView(#82)/ common barrel(#83)之后,renderer 下仍有三个职责混杂的单体组件(复杂状态机 / 纯算法 + 渲染糅在一处)。本 PR 按「纯算法 → util;状态机 → hook;渲染 → 瘦组件」拆分,运行时行为零变化(纯结构搬运;依赖数组 / 事件时序 / eslint-disable 兜底原样保留)。
三笔独立 commit:
1.
refactor(diff)DiffSearchPanel 576 → ~190 行diff/search/diff-search.ts:纯跨文件搜索逻辑(runSearch + findChangedIndices / expandToContext / stripLeadingIndent / findMatchSpan / countLines / loadContent)+ 类型 / 常量,无 React 依赖diff/search/colorize.ts:colorizeAll(Monacoeditor.colorize异步语法着色)diff/search/useDiffSearch.ts:搜索状态机 hook(query / 大小写持久化 / 结果 / loading / 折叠态 + 去抖 + 内容缓存 + 自动聚焦)2.
refactor(drafts)DraftZone 531 → ~230 行drafts/useDraftZone.ts:read/edit/publish 状态机 hook(全部 state / ref / effect / handler;取消四档逻辑runCancelLogic被取消按钮 / unmount cleanup / Esc 共用,整体搬进 hook 保持行为一致)3.
refactor(chat)ChatInputBar 479 → ~240 行chat/utils/parse-command.ts:纯命令解析parseChatCommand→ 判别式结果,无 i18n / 副作用chat/hooks/useChatInput.ts:输入栏状态机(输入 / 提交 / 自动补全 / 历史回放 / 停止请求)chat/hooks/useTextareaAutosizeDrag.ts:textarea 顶边拖拽调高行为保留 & 外部面
三个文件的公共导出名与路径均不变,外部引用为单点(DiffSearchPanel ← DiffView;DraftZone ← DraftZoneList;ChatInputBar ← ChatPane),零波及。
验证
lint零警告 ✓ ·typecheck✓ ·build✓ ·test(仅 packages;repo-mirror 5 个 git-CLI 环境性失败属已知、与本改动无关)。人工回归重点:搜索(去抖 / 大小写持久化 / 着色 / 折叠 / 跳转 / Esc 退出)、草稿(read↔edit / 四档取消 / Cmd+Enter 发布 / 切文件自动保存 / 删除确认)、输入栏(命令解析与未知报错 / 自动补全 Up/Down/Enter/Tab/Esc / 历史回放 / textarea resize / 发送停止 / IME 不拦截)。
关联里程碑 代码质量重构 (#3)。
🤖 Generated with Claude Code